import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import './home.dart';
import '../cart/cart.dart';
import '../search/search.dart';
import '../profile/profile.dart';
import './bottom.dart';

class HomePage extends StatefulWidget {
  HomePage({Key key}) : super(key: key);

  _HomePage createState() => _HomePage();
}

class _HomePage extends State<HomePage> {

  final List tabPage = [
    Index(),
    Search(),
    Cart(),
    Profile()
  ];

  int currentIndex = 0;
  var currentPage;
  @override
  void initState() {
    currentPage  = tabPage[currentIndex];
    super.initState();
  }

  

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('首页')
      ),
      bottomNavigationBar: BottomNavigationBar(
        type: BottomNavigationBarType.fixed,
        currentIndex: currentIndex,
        items: bottomTabs,
        onTap: (index) {
          setState(() {
            currentIndex = index;
            currentPage = tabPage[index];
          });
        },
      ),
      body: currentPage
    );
  }
}

